package com.xiaoKe.zhonghzu.ui.data;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.xiaoKe.zhonghzu.R;
import com.xiaoKe.zhonghzu.databinding.ItemDataListBinding;
import com.xiaoKe.zhonghzu.databinding.ItemEnvListBinding;
import com.xiaoKe.zhonghzu.global.bean.GeneralData;
import com.xiaoKe.zhonghzu.global.tool.ResourceTool;
import com.xiaoKe.zhonghzu.ui.onClick.OnClickListenerPositionInt;
import com.xiaoKe.zhonghzu.ui.onClick.OnClickListenerPositionObject;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * @ProjectName : xiaoke-pad-zhongzhu
 * @Author : Shijingna
 * @Time : 2024/9/4 15:38
 * @Description : 文件描述
 */
public class DataListAdapter extends RecyclerView.Adapter<DataListAdapter.ViewHolder> {

    List<GeneralData> listTest;


    @NonNull
    @NotNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        ItemDataListBinding binding = ItemDataListBinding.inflate(inflater, parent, false);
        return new ViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull ViewHolder holder, int position) {
        GeneralData generalData = listTest.get(position);
        holder.binding.lineBg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onClickListenerPositionInt.onItemClick(generalData.getName().toString());
            }
        });
        holder.binding.title.setText(generalData.getK().toString());
        holder.binding.time.setText(generalData.getV().toString());

    }

    @Override
    public int getItemCount() {
        return listTest.size();
    }

    public void setData(List<GeneralData> listTest) {
        this.listTest  =listTest;
        notifyDataSetChanged();

    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        final ItemDataListBinding binding;
        ViewHolder(ItemDataListBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
    public OnClickListenerPositionObject onClickListenerPositionInt;

    public void setOnClickListenerPositionInt(OnClickListenerPositionObject onClickListenerPositionInt) {
        this.onClickListenerPositionInt = onClickListenerPositionInt;
    }
}
